<script type="text/javascript">
  (function () {

    $(document).on('change', '.btn-file :file', function () {
      var input = $(this);
      var numFiles = input.get(0).files ? input.get(0).files.length : 1;
      var label = input.val().replace(/\\/g, '/').replace(/.*\//, '');

      input.trigger('fileselect', [numFiles, label]);
    });


    $(document).ready( function () {
      $('.btn-file :file').on('fileselect', function (aE, aNumFiles, aLabel) {

        var input = $(this).parents('.input-group').find(':text');
        var log = aNumFiles > 1 ? aNumFiles + ' files selected' : aLabel;

        if (input.length) {
          input.val(log);
        } else {
          if (log) {
            alert(log);
          }
        }
      });
    });

  })();
</script>
